package com.common.help.test02;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class SocketClient1 {

	public static void main(String[] args) throws Exception {
		
		String address = "127.0.0.1";
		int port = 55533;
		
			String message = "hello socket";
			Socket socket = new Socket(address, port);
			
			OutputStream out = socket.getOutputStream();
			out.write(message.getBytes());
			
			socket.shutdownOutput();//客户端招手 我们已经写完了 等待服务端相应
			
			byte[] b = new byte[2048];
			int len;
			 StringBuilder sb = new StringBuilder();
			InputStream is = socket.getInputStream();
			while((len=is.read(b))!=-1){
				sb.append(new String(b, 0, len, "UTF-8"));
			}
			System.out.println("get message from server:"+sb);
			is.close();
			out.close();
			socket.close();
	}
}